﻿#pragma once

#include "Device.h"

namespace DeviceLayer
{

/**
 * @brief 示例设备：可调稳压电源
 */
class DeviceDemoVoltage : public Device
{
    DECLARE_DYNAMIC_CREATE(DeviceDemoVoltage)
private:
    bool switchedOn { false };
    float voltage { 0 };
    float minVoltage { 0 };
    float maxVoltage { 0 };
    bool warning { false };
public:

    DeviceDemoVoltage();
    DeviceDemoVoltage(DeviceDemoVoltage &) = delete;

    void PowerSwitch(bool on)
    {
        switchedOn = on;
    }
    bool IsOn() const
    {
        return switchedOn;
    }

    inline float GetVoltage() const { return switchedOn ? voltage : 0; }
    inline void SetVoltage(const float voltage)
    {
        this->voltage = voltage;
        warning = (voltage > maxVoltage || voltage < minVoltage);
    }
    inline bool GetWarning() const { return warning; }


    virtual bool InitFromSettingData(const QString& path) override;
    virtual bool QueryData() override;
};

}
